﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Ebada.Modules.Vehicle
{
    /// <summary>
    /// 车辆公里数登记编辑
    /// </summary>
    public partial class frmVehicleKilometerEdit : FormBase, IPopupFormEdit {
        SortableSearchableBindingList<mOrg> m_OrgID = new SortableSearchableBindingList<mOrg>();
        SortableSearchableBindingList<Empolyees> m_Employ= new SortableSearchableBindingList<Empolyees>();

        public frmVehicleKilometerEdit()
        {
            InitializeComponent();
        }
        private void frmVehicleKilometerEdit_Load(object sender, EventArgs e)
        {

           

        }
        void dataBind() 
        {

            this.luVehicleID.DataBindings.Add("EditValue", rowData, "VehicleID");
            this.daeStartDate.DataBindings.Add("EditValue", rowData, "StartDate");
            this.txtStrartKilometer.DataBindings.Add("EditValue", rowData, "StrartKilometer");
            this.deeEndDate.DataBindings.Add("EditValue", rowData, "EndDate");
            this.txtEndKolometer.DataBindings.Add("EditValue", rowData, "EndKolometer");
            this.txtRealKolometer.DataBindings.Add("EditValue", rowData, "RealKolometer");

            this.meRemark.DataBindings.Add("EditValue", rowData, "Remark");
           
        }
       
        #region IPopupFormEdit Members
        private VehicleKilometer rowData = null;

        public object RowData {
            get {
                return rowData;
            }
            set {
                if (value == null) return;
                if (rowData == null) {
                    this.rowData = value as VehicleKilometer;
                    dataBind();
                    InitComboBoxData();
                } else {
                    ConvertHelper.CopyTo<VehicleKilometer>(value as VehicleKilometer, rowData);
                }
            }
        }

        #endregion

        private void InitComboBoxData() 
        {
            IList<Vehicles> vehi_list = MainHelper.PlatformSqlMap.GetList<Vehicles>("");
            this.SetComboBoxData2(this.luVehicleID, "VehicleNumber", "VehicleID", "请选择", "车牌号码", vehi_list);

        }

        //车牌号选择器
        public void SetComboBoxData2(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, IList<Vehicles> post)
        {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }
        

        private void btnOK_Click(object sender, EventArgs e)
        {
          
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
       
       
        //车牌号选择
        private void luVehicleID_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 1)
            {

                frmVehiclesSeletcter frm = new frmVehiclesSeletcter();
                frm.InitData_Slect("");
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    luVehicleID.Text = frm.SelectObj.VehicleNumber;
                    rowData.VehicleNumber = frm.SelectObj.VehicleNumber;
                    luVehicleID.CancelPopup();
                }
            }

        }

        private void luVehicleID_EditValueChanged(object sender, EventArgs e)
        {

        }
      

      
    }
}